package zozopo.manual;

import java.io.IOException;
import java.sql.Connection;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import zozopo.database.BusiDatabaseManager;
import zozopo.manual.operations.ReleaseOS;
import zozopo.manual.operations.ReleaseTB;
import zozopo.manual.operations.ReplyOS;
import zozopo.user.operations.UserTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class ReplyDeleteForAjaxAction extends ActionSupport implements Action ,SessionAware,ServletRequestAware,ServletResponseAware{
	
	private Map<Object, Object> session;
	private int replyId;
	public int getReplyId() {
		return replyId;
	}
	public void setReplyId(int replyId) {
		this.replyId = replyId;
	}
	private HttpServletRequest request;
	private HttpServletResponse response;
	
	public String execute(){
		
		
		ReplyOS replyOS = new ReplyOS();
	
		UserTB user = (UserTB) session.get("userInfo");

		try {
			if(('0' == user.getUser_limitflag().charAt(3))){
				response.getWriter().write(NONE);
			}else{
				if(replyOS.deleteSubject(replyId)){
					response.getWriter().write(SUCCESS);
				}else{
					response.getWriter().write(ERROR);
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			try {
				response.getWriter().write(ERROR);
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			
		}
		
		replyOS.releaseConnection();
		return NONE;
	}
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}
	
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		request = arg0;
	}

	public void setServletResponse(HttpServletResponse arg0) {
		// TODO Auto-generated method stub
		response = arg0;
	}
}
